<?php
if (preg_match_all("/<table[^>]*>(.*?)<\/table>/si", $unit, $groups, PREG_SET_ORDER))
{
    foreach ($groups as $i => $group)
    {
        foreach ($group as $matchs)
        {
            if ($a = preg_match_all("/<tr class=\"(odd|even)\"><td[^>]*>(.*?)<\/td><td[^>]*>(.*?)<\/td>\s*<td[^>]*>\s*<a[^>]*href=\"([^\"]+)\"[^>]*>(.*?)<\/a>\s*<\/td>\s*<td[^>]*>.*?(\w{3})\.gif.*?<\/td>\s*<td[^>]*>\s*<a[^>]*href=\"([^\"]+)\"[^>]*>(.*?)<\/a><\/td>\s*<td[^>]*>\s*(<span[^>]*>\s*)?<a[^>]*href=\"([^\"]+)\"[^>]*>(.*?)<\/a>(\s*<\/span>)?\s*<\/td>\s*<td[^>]*>\s*<a[^>]*href=\"([^\"]+)\"[^>]*>(.*?)<\/a><\/td>\s*<td[^>]*>.*?(\w{3})\.gif.*?<\/td>\s*<\/tr>/si", $matchs, $match, PREG_SET_ORDER))
            {
                foreach ($match as $j => $records)
                {
                    $results['group'][$i][$j]['match']       = strip_tags(trim($records[2]));
                    $results['group'][$i][$j]['date']        = strip_tags(trim($records[3]));
                    $results['group'][$i][$j]['venue_link']  = strip_tags(trim($records[4]));
                    $venue = strip_tags(trim($records[5]));
                    if ( strstr($venue, 'Port Elizabeth') )
                        $venue = 'Port Elizabeth';
                    else if ( strstr($venue, 'Bloemfontein') )
                        $venue = 'Bloemfontein';
                    else if ( strstr($venue, 'Johannesburg') )
                        $venue = 'Johannesburg';
                    else if ( strstr($venue, 'Pretoria') )
                        $venue = 'Pretoria';
                    $results['group'][$i][$j]['venue_text']  = $venue;
                    $results['group'][$i][$j]['team1_flag']  = strip_tags(trim($records[6]));
                    $results['group'][$i][$j]['team1_link']  = strip_tags(trim($records[7]));
                    $results['group'][$i][$j]['team1_text']  = strip_tags(trim($records[8]));
                    $results['group'][$i][$j]['result_link'] = strip_tags(trim($records[10]));
                    $results['group'][$i][$j]['result_text'] = strip_tags(trim($records[11]));
                    $results['group'][$i][$j]['team2_link']  = strip_tags(trim($records[13]));
                    $results['group'][$i][$j]['team2_text']  = strip_tags(trim($records[14]));
                    $results['group'][$i][$j]['team2_flag']  = strip_tags(trim($records[15]));
                }
            }
        }
    }
}
?>